package com.frame.common.model;

import com.frame.para.ParametersUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

public class PageInfo<T> implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Getter
	@Setter
	@ApiModelProperty(value="每页显示数据行数")
	private int showCount = 10; 
	
	@ApiModelProperty(value="总页数")
	private int totalPage;
	
	@Getter
	@Setter
	@ApiModelProperty(value=" 总记录数")
	private int totalResult; 
	
	@Getter
	@Setter
	@ApiModelProperty(value="当前页")
	private int currentPage = 1; 
	
	@Getter
	@Setter
	@ApiModelProperty(value="数据集")
	private List<T> Data;
	
	@ApiModelProperty(value="查询开始位置")
	private int currentResult;

	@Getter
	@Setter
	@ApiModelProperty("当前分页的时间戳")
	private Long timeStamp;

	@Getter
	@Setter
	@ApiModelProperty("排序字段")
	private String sortField = "";
	
	@Getter
	@Setter
	@ApiModelProperty("排序顺序  desc|asc")
	private String sortOrder = "";
	
	public PageInfo(){
		super();
	}

	public PageInfo(ReqPageInfoVO reqPageInfoVO){
		if(!ParametersUtil.isNull(reqPageInfoVO.getShowCount())){
			this.setShowCount(reqPageInfoVO.getShowCount());
		}

		if(!ParametersUtil.isNull(reqPageInfoVO.getCurrentPage())) {
			this.setCurrentPage(reqPageInfoVO.getCurrentPage());
		}
	}


	public int getTotalPage() {
		return (int) (totalResult%showCount)==0?(totalResult/showCount):((totalResult/showCount)+1);
	}



	public int getCurrentResult() {
		// 计算从第几条获取数据
		currentResult = (currentPage - 1) * showCount;
		return currentResult;
	}

	public int getEnd(){
		return (showCount*currentPage-1) > totalResult ? totalResult : (showCount*currentPage-1);
	}




}
